<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      margin: 0;
    }
    #map {
      width: 100vw;
      height: 100vh;
    }
  </style>
</head>
<body>
  <div id="map"></div>
  <script type="text/javascript">
    window._AMapSecurityConfig = {
        serviceHost:'http://127.0.0.1:3000/_AMapService',
        securityJsCode: '689cef8e5173f8da6eb31e62be8090db',
    }
  </script>
  <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=758243bc2f718078ab06b843cdf7bf1e&plugin=AMap.Driving"></script>
  <script>

    function coord (lon, lat) {
      return new AMap.LngLat(lon, lat);
    }

    const map = new AMap.Map('map', {
        zoom: 13, //级别
        // center: [116.397428, 39.90923], //中心点坐标
        center: [116.415061, 39.90375], //中心点坐标
        viewMode: '3D', //使用3D视图
    });

    //构造路线导航类
    const driving = new AMap.Driving({
        map,
        policy: AMap.DrivingPolicy.LEAST_FEE,
    });
    // 根据起终点经纬度规划驾车导航路线
    driving.search(coord(106.329117, 29.607746), coord(106.37291, 29.600752), function(status, result) {
        console.log(result);
      // result 即是对应的驾车导航信息，相关数据结构文档请参考  https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingResult
        if (status === 'complete') {
            // log.success('绘制驾车路线完成')
        } else {
            // log.error('获取驾车数据失败：' + result)
        }
    });
    const a = new AMap.Driving({
        map,
        policy: AMap.DrivingPolicy.LEAST_DISTANCE,
        showTraffic: false
    });
    // 根据起终点经纬度规划驾车导航路线
    a.search(coord(106.329117, 29.607746), coord(106.37291, 29.600752), function(status, result) {
        // result 即是对应的驾车导航信息，相关数据结构文档请参考  https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingResult
        if (status === 'complete') {
          const { steps } = result.routes[0];
          const lastStep = steps[steps.length - 1];
          console.log(steps
              .map(s => coord(
                s.start_location.lng,
                s.start_location.lat,
              ))
              .concat(coord(
                lastStep.end_location.lng,
                lastStep.end_location.lat,
              )));
          const polyline = new AMap.Polyline({
            path: steps
              .map(s => s.start_location)
              .concat(lastStep.end_location),
            strokeColor: 'red',
            lineJoin: 'round',
            strokeOpacity: 1,
            strokeWeight: 10,
          });
          map.add(polyline);
        } else {

        }
    });
  </script>
</body>
</html>